import time
import pytest
import allure
import TestCase

from Base.InitDriver import init_driver
from Page.CommonPage import CommonPage
from Utils.XiaoMaUtils import XiaoMaUtils


@allure.feature('TestCase_03: 点击添加执行事件按钮弹出选择添加执行事件弹窗		')
@allure.issue(
    'https://www.tapd.cn/54441127/sparrow/tcase/view/1154441127001070686?url_cache_key=5b07a59231afaf505fb7dc2f4205dfae')
class TestCaseYomi03:
    def setup_class(self):
        self.driver = init_driver()
        # 实例化页面
        # 桌面
        self.launcher_index_page = CommonPage(self.driver).get_launcher_index_page()
        self.launcher_app_list_page = CommonPage(self.driver).get_launcher_app_list_page()
        # 语音训练
        self.yomi_index_page = CommonPage(self.driver).get_yomi_index_page()
        self.yomi_car_control_page = CommonPage(self.driver).get_yomi_car_control_page()
        self.yomi_car_window_page = CommonPage(self.driver).get_yomi_car_window_page()
        self.yomi_delete_toast_page = CommonPage(self.driver).get_yomi_delete_toast_page()
        self.yomi_details_page = CommonPage(self.driver).get_yomi_details_page()
        self.yomi_music_page = CommonPage(self.driver).get_yomi_music_page()
        self.yomi_navigation_page = CommonPage(self.driver).get_yomi_navigation_page()
        self.yomi_new_page = CommonPage(self.driver).get_yomi_new_page()
        self.yomi_online_radio_page = CommonPage(self.driver).get_yomi_online_radio_page()
        self.yomi_passage_page = CommonPage(self.driver).get_yomi_passage_page()
        self.yomi_quit_toast_page = CommonPage(self.driver).get_yomi_quit_toast_page()
        self.yomi_radio_page = CommonPage(self.driver).get_yomi_radio_page()
        self.yomi_skill_list_page = CommonPage(self.driver).get_yomi_skill_list_page()
        self.yomi_skill_page = CommonPage(self.driver).get_yomi_skill_page()
        self.yomi_temperature_page = CommonPage(self.driver).get_yomi_temperature_page()
        self.yomi_volume_page = CommonPage(self.driver).get_yomi_volume_page()
        self.yomi_weather_page = CommonPage(self.driver).get_yomi_weather_page()
        self.yomi_delete_page = CommonPage(self.driver).get_yomi_delete_page()

    def teardown_class(self):
        XiaoMaUtils.close_app('launcher')
        # XiaoMaUtils.clear_data('personal')
        self.driver.quit()

    @allure.story('step1:点击应用页')
    @pytest.mark.run(order=31)
    def test_yomi_03_1_click_list(self):
        try:
            self.launcher_index_page.click_app_list()
        except Exception as e:
            raise e
        finally:
            allure.attach(self.driver.get_screenshot_as_png(), XiaoMaUtils.get_current_time(),
                          allure.attachment_type.PNG)

    @allure.story("step2: 点击列表中的yomi训练图标")
    @pytest.mark.run(order=32)
    def test_yomi_03_2_click_yomi(self):
        try:
            self.launcher_app_list_page.click_appname(TestCase.YOMI)
            a = self.yomi_skill_list_page.is_display_yomi_skill_list()
            if a == True:
                self.yomi_skill_list_page.click_skill_name_title()
                self.yomi_delete_page.is_display_yomi_delete()
                self.yomi_delete_toast_page.click_no()
                self.yomi_delete_toast_page.click_sure()
                self.yomi_index_page.is_display_yomi_index()
            else:
                self.yomi_index_page.is_display_yomi_index()
        except Exception as e:
            raise e
        finally:
            allure.attach(self.driver.get_screenshot_as_png(), XiaoMaUtils.get_current_time(),
                          allure.attachment_type.PNG)

    @allure.story("step3: 点击添加技能,查看是否进入添加技能页,然后点击技能按钮,查看是否存在技能页")
    @pytest.mark.run(order=33)
    def test_yomi_03_3_click_yomi(self):
        try:
            self.yomi_index_page.click_create()
            self.yomi_details_page.is_display_yomi_details()
            self.yomi_details_page.click_add_skill()
            self.yomi_skill_page.is_display_yomi_skill()
        except Exception as e:
            raise e
        finally:
            allure.attach(self.driver.get_screenshot_as_png(), XiaoMaUtils.get_current_time(),
                          allure.attachment_type.PNG)


if __name__ == '__main__':
    # pass
    pytest.main("-s testcase_yomi_03.py")
